<template>
  <ul class="menu" @click="setIndex">
    <li class="menu-item" data-key="0">
      <router-link to="/">主页</router-link>
    </li>
    <li class="menu-item" data-key="1">
      <router-link to="/game">项目</router-link>
    </li>
    <li class="menu-item" data-key="2">
      <router-link to="/contact">联系</router-link>
    </li>
  </ul>
</template>

<script>
export default {
  data () {
    return {
      index: 0
    }
  },
  methods: {
    setIndex (e) {
      if (e.target.nodeName === 'UL') { return }
      this.index = e.target.parentElement.dataset.key
    },
    linkTo (path) {
      this.$router.push({path})
    }
  }
}
</script>

<style lang="scss" scoped>
.menu {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
  &-item {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 1rem;
    &:hover {
      background-color: rgba(0, 0, 0, 0.2);
    }
    a {
      color: #2c3e50;
    }
    .is-active {
      color: blue;
    }
  }
}
</style>
